﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;

public class SpawnManager : Photon.MonoBehaviour 
{
	public Transform[] spawnPoints;
	[HideInInspector]public Transform spawnPoint;
	[HideInInspector]public GameObject player;

	public GameObject deathCam;
	public GameObject lifeCam;
	[HideInInspector] public bool alive = false;
	[HideInInspector] public PhotonView photView;
	private LifeController lifeController;
	public float deathDuration = 2;
	public GameObject deadTurret;
	public GameObject[] bases = new GameObject[2];

	void Awake()
	{
		photView = PhotonView.Get(this);
	}
	public void Die()
	{	
		StartCoroutine(WaitThenRespawn());
		alive = false;
		deathCam.SetActive (true);
		lifeCam.SetActive (false);
	}
	public IEnumerator WaitThenRespawn()
	{
		yield return new WaitForSeconds(deathDuration);
		Respawn();
	}
	public void Respawn()
	{	
		lifeController.health = lifeController.healthSkill.level;
		player.transform.position = spawnPoint.position;
		alive = true;
		deathCam.SetActive (false);
		lifeCam.SetActive (true);
		lifeController.Respawn();
	}
	public void SetLocalPlayer(GameObject me)
	{
		player = me;
		alive = true;
		lifeController = me.GetComponent<LifeController>();
		lifeCam = lifeController.lifeCam; 
	}
	public void RemoveLocalPlayer()
	{
		player = null;
		alive = false;
		lifeController = null;
		lifeCam = null;
	}
	public void BaseDeath(int team)
	{	
		Debug.Log(team);
	}




}
